 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
import { MainStrategy } from "GameLoop/WorldState/EntityManager/CreateStrategy/MainStrategy";
import { priority } from "utils/constants/definetypes";
import { Roles } from "utils/creep/setups";
import { generateUniqueId } from "utils/utils";

/**
 * 升级时的。放置site
 */
export class PlaceLevelNormalPlanDecision< T extends "room"="room"> extends ABaseDecision<T>
{
   
    public isExpired(event: AddRoomEvent, region: string): boolean 
    {
       
        return true;
    }
    public makeTask(event: AddRoomEvent, region: string): IDecisionCode<T>|false
    {
        const room = Game.rooms[event.region];
        this.WorldGetter.Station.tryRegisterRoom(event.region);
        const plan = this.WorldGetter.Station.PollBlueplan(event.region);
        if(plan)
        {
            // 放置site任务。根据等级
           
            const planesite = plan.getNormalPlan();
            const curlevel = room.controller?.level as number;
            
            const curindex =  planesite.SiteQueue.levelLimit[curlevel];
            const preindex =  planesite.SiteQueue.levelLimit[curlevel-1];

            const thisplans:IPlanItem[] =planesite.SiteQueue.items.slice(preindex,curindex);
            // 如果到6级额外补充一个minerial的 container
            if(curlevel >=6)
            {
                // const pos = room.getEntity("MinerialEntity").getWorkPosition() ;
                // thisplans.push({pos:pos,type:STRUCTURE_CONTAINER});
                // 补充一个lab的container
                
                thisplans.push({pos:room.getEntity('LabEntity').unBoostPosition(),type:STRUCTURE_CONTAINER});
            }
            const task :ITaskDeclare[T]={
                id:generateUniqueId(),
                priority:priority.S,
                ttl:5000,
                type:"room",
                data:{
                    type:"placePlan",
                    arg:{
                        roomName:room.name,
                        plan:thisplans
                    },
                },
                shard:0,
                
            }
            //   thissite.  
            const code:IDecisionCode<T>={
                region:event.region,
                task:[task],
                isunique:false,
            }
            return code
        }
        else 
        {
            Memory.Debug[`放置plan任务${event.region}`]="没有plan 放置失败";
            room.log(`error`,`没有plan 放置失败`);
        }
        return false;
        // return code
    }
    
}